package org.kolonitsky.alexey.net
{
    import flash.system.Security;
    
    import org.kolonitsky.alexey.collections.IList;

    /**
     * PicassaRSSService enreach rss by additional information and change URL
     * according documentation for load crossdomain files.
     */
    public class PicasaRSSService extends RSSService
    {
        /**
         * Google photo domain for user content with not markeging name. This
         * host contain crossdomain policy.
         */
        public static const FLASH_DOMAIN:String = "ggpht.com";
        
        /**
         * Long google photo domain is default. Not contain crossdomain policy
         * file.
         */
        public static const NOT_FLASH_DOMAIN:String = "googleusercontent.com";
        
        /**
         * URL to google crossdomain policy file.
         */
        public static const GOOGLE_PHOTO_CROSSDOMAIN:String =
            "http://photos.googleapis.com/data/crossdomain.xml";
        
        public function PicasaRSSService()
        {
            //Security settings for google photos API
            Security.loadPolicyFile(GOOGLE_PHOTO_CROSSDOMAIN);
            
            super();
        }




        //----------------------------------------------------------------------
        //
        //  Implementation IList interface
        //
        //----------------------------------------------------------------------
        
        public function getItemAt(index:int):Object
        {
            var replacePattern:RegExp = new RegExp(NOT_FLASH_DOMAIN);
            var item:Object = super.getItem(index);
            item.image = String(item.image).replace(replacePattern, FLASH_DOMAIN);
            item.image = String(item.image).replace(/https:\/\//, "http://");
            
            item.thumbnail = String(item.thumbnail).replace(replacePattern, FLASH_DOMAIN);
            item.thumbnail = String(item.thumbnail).replace(/https:\/\//, "http://");
            
            return item;
        }
    }
}